TWB.New_Module({
	///////////////////////////
	name : "AcademyBulk",    //
	author : "enduo",        //
	version : 1.0,           //
	///////////////////////////
	
	H : {},
	Single : function(){
		if(!TWB.logged()){
			return alert(TWB.lang("notlogged"));
		}
		if(TWB.Modules.Icons.Screen()!="snob"){
			TWB.Processor.start("singlebulk","Modules.AcademyBulk.Single","*",true);
			TWB.Modules.Icons.GoTo("snob");
		}
		else{
			if(TWB.WorldSet('snob/gold')){
				// GET H
				var a=TWB.Xpath("//a[contains(@href,'action=coin')]",9);
				if(!a){
					return alert(TWB.lang("nobulk"));
				}
				TWB.Modules.AcademyBulk.H[TWB.World(true)]=a.href.match(/h=(\w+)/)[1];
				// Gold Coins
				var tds=TWB.Xpath("//*[@id='content_value']//table[2]//tbody/tr/td[2]/table[5]//td",6);
				var prices=tds[0].textContent.replace(/\./g,"").match(/\d+/g);
				var res=TWB.Xpath("//table[@class='header-border menu_block_right']//table[@class='box smallPadding']//tr",9).textContent.match(/\d+/g);
				var x=Math.min(Math.floor(res[0]/prices[0]),Math.floor(res[1]/prices[1]),Math.floor(res[2]/prices[2]));
				if(x>0){
					var result=prompt(TWB.lang("snobulk"),x);
					x=Math.min(x,result);
					TWB.Modules.AcademyBulk.BulkSingle(x);
				}
				else{
					alert(TWB.lang("nobulk"));
				}
			}
			else{
				// Packets
			}
		}
	},
	BulkSingle : function(x){
		var world=TWB.World(true);
		if(typeof TWB.Servers[world.replace(/\d+/,"")]=="undefined"){
			return alert(TWB.lang("servernotsup"));
		}
		
		TWB.$.ajax({
			url : TWB.Modules.Icons.GoTo('snob',undefined,true)+"&action=coin&h="+TWB.Modules.AcademyBulk.H[TWB.World(true)],
			type : "GET",
			async : true,
			success : function(){
				x--;
				if(x>0){
					TWB.Modules.AcademyBulk.BulkSingle(x);
				}
				else{
					TWB.Modules.Icons.GoTo("snob");
				}
			}
		});
	},
});